<?php

namespace App\Model;

class Role extends Model
{
    protected ?string $table = 'roles';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected array $fillable = [
        'role_key', 'name', 'description',
    ];
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected array $casts = [
        'id' => 'integer',
        'role_key' => 'string',
        'name' => 'string',
        'created_at' => 'datetime',
        'updated_at' => 'datetime'
    ];

    /**
     * 角色中的管理员.
     * @return \Hyperf\Database\Model\Relations\BelongsToMany
     */
    public function administrators()
    {
        return $this->belongsToMany(Administrator::class, 'administrator_role', 'role_id', 'administrator_id');
    }

    public function menus()
    {
        return $this->belongsToMany(\App\Model\Menu::class, 'role_menu', 'role_id', 'menu_id');
    }

    public function permissions()
    {
        return $this->belongsToMany(\App\Model\Permission::class, 'role_permission', 'role_id', 'permission_id');
    }
}